<?php
defined("_ALLOW") or die ("Access denied");
global $lang;
?>
<?php
include_once("class/cproduct.php");
global $objproduct;
$urlpaging="index.php?module=com_searchproduct";
global $strwhere; 
$strwhere = "";
if(isset($_GET['giaodich']))
{
	$giaodich = $_GET['giaodich'];
	$strwhere .= "id_giaodich = $giaodich";
	$urlpaging .= "&giaodich=" . $giaodich;
}
else
{
	$dientich = $_GET['dientich'];
	$duongrong = $_GET['duongrong'];
	$keyword = $_GET['keyword'];
	$huong = $_GET['huong'];	
	$gia = $_GET['gia'];
	if ($dientich>0)
	{
	switch ($dientich) {
		case 1:
			$strwhere .= "tongdientich<=100";
			break;
		case 2:
			$strwhere .= "tongdientich>100 AND tongdientich<=150";
			break;
		case 3:
			$strwhere .= "tongdientich>150 AND tongdientich<=200";
			break;
		case 4:
			$strwhere .= "tongdientich>200 AND tongdientich<=300";
			break;
		case 5:
			$strwhere .= "tongdientich>800";
			break;
		
	}
	}
	$urlpaging .= "&dientich=" . $dientich;
	
	if ($duongrong>0)
	{
		if($strwhere != "")
		{
			$strwhere .= " AND ";
		}
	switch ($duongrong) {
		case 1:
			$strwhere .= "duongrong<=10";
			break;
		case 2:
			$strwhere .= "duongrong>10 AND duongrong<=15";
			break;
		case 3:
			$strwhere .= "duongrong>15 AND duongrong<=20";
			break;
		case 4:
			$strwhere .= "duongrong>20";
			break;
		
	}
	}
	$urlpaging .= "&duongrong=" . $duongrong;
			
	if ($huong>0)
	{
		if($strwhere != "")
			$strwhere .= " AND id_huong=$huong";
		else
			$strwhere .= "id_huong=$huong";
	}
	$urlpaging .= "&huong=" . $huong;
	
	if ($gia>0)
	{
		if($strwhere != "")
		{
			$strwhere .= " AND ";
		}
	switch ($gia) {
		case 1:
			$strwhere .= "tongtien <= 500000000";
			break;
		case 2:
			$strwhere .= "tongtien > 500000000 AND tongtien <= 1000000000";
			break;
		case 3:
			$strwhere .= "tongtien > 1000000000 AND tongtien<=1500000000";
			break;
		case 4:
			$strwhere .= "tongtien>1500000000 AND tongtien<=2000000000";
			break;
		case 5:
			$strwhere .= "tongtien>20000000000 AND tongtien<=3000000000";
			break;
		case 6:
			$strwhere .= "tongtien>3000000000 AND tongtien<=5000000000";
			break;
		case 7:
			$strwhere .= "tongtien>50000000000";
			break;
	}
	}
	$urlpaging .= "&gia=" . $gia;
	
	if($keyword != "")
	{
		if($strwhere == "")
		{
		$strwhere .= "(title) LIKE '%$keyword%' COLLATE latin1_swedish_ci ";
		}
		else
		{
		$strwhere .= " AND (title) LIKE '%$keyword%' COLLATE latin1_swedish_ci ";

		}
	}
	$urlpaging .= "&keyword=" . $keyword;

}

?>
<script language="javascript">
var url = "<?php echo $urlpaging; ?>";
function GotoPage (page) {
	var urltopage;
	urltopage = url + "&curPage=" + page;
	location.href = urltopage;
//	Ajax_Goto(url);
}
</script>
<div class="td_listproduct_tt">
<?php
	global $totalRows;
	$totalRows = $objproduct->CountFill($strwhere);
?>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  
	  <tr>
		<td valign="top" style="padding:5 5 5 5;" >
			<?php
			if ($totalRows > 0) {
				global $maxRows;
				$maxRows = 50;
				global $maxPages;
				$maxPages = 10;
				global $curPage;
				include_once("common/paging.php");
				$paging = Paging_GetPaging();
				$beginrow = ($curPage-1) * $maxRows;
				global $array;
				$array = $objproduct->Fill($strwhere, $maxRows, $beginrow);
				include("listproject.php");
				echo $paging;
			}
			else
			{
			?>
			 <div style="font-family:Tahoma; font-size:12px; font-weight:bold; color:#FF0000; text-align:center; text-transform:uppercase;">Không có thông tin cần tìm.</div>
			 <?php
			 }
			 ?>
			
		</td>
	  </tr>
	</table>
</div>